﻿<Window x:Class="OneShoppingList.MainWindow"
        xmlns:local="clr-namespace:OneShoppingList"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:con="http://schemas.kent.boogaart.com/converters"
        xmlns:wpftk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
        mc:Ignorable="d" Title="One Shopping List"
        DataContext="{Binding Main, Source={StaticResource Locator}}" 
        Height="600" Width="350" ResizeMode="CanResizeWithGrip" 
        ShowInTaskbar="True" WindowStartupLocation="CenterScreen" 
        WindowState="Normal"  WindowStyle="None" MouseLeftButtonDown="Window_MouseLeftButtonDown" 
        MinWidth="300" MinHeight="500" MaxWidth="400" Icon="/OneShoppingList;component/Icons/ApplicationIcon.png" 
        AllowsTransparency="True" Background="Beige" FontWeight="Medium">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <Border BorderThickness="1" BorderBrush="Black">
        <Grid Margin="6">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Grid Grid.Row="0" Background="DodgerBlue" Margin="-6,-6,-6,3" HorizontalAlignment="Left" Width="348">
                <StackPanel  Margin="12,3,0,3" Orientation="Horizontal">
                    <Button  HorizontalAlignment="Right" VerticalAlignment="Center" 
                    Style="{StaticResource ResourceKey=RoundButton}"
                    Margin="-6,-12,6,-12"
                    Background="Transparent"
                    BorderThickness="0"
                    Opacity="1"
                    Name="navigateButton" 
                    Click="navigateButton_Click">
                        <Image Source="/OneShoppingList;component/Icons/ApplicationIcon32.png" Stretch="None" />
                    </Button>
                    <StackPanel Orientation="Vertical">
                        <TextBlock Text="ONE SHOPPING LIST" VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="SemiBold" FontSize="15" Foreground="White"/>
                        <!--<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding ShoppingList.Count}" FontWeight="Bold" Foreground="White"/>
                        <TextBlock Text=" Items" FontWeight="Bold" Foreground="White"/>
                    </StackPanel>-->
                    </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal" 
                        HorizontalAlignment="Right" VerticalAlignment="Center"                          
                        Margin="0,0,6,0">
                    <Button  Style="{StaticResource ResourceKey=VisibleRoundButton}"
                            Background="Transparent"
                            BorderThickness="0"
                            Command="{Binding Main.SaveCommand, Source={StaticResource Locator}}"
                            Name="saveButton">
                        <Image Source="/OneShoppingList;component/Icons/SaveWhiteBig.png" Stretch="None"/>
                    </Button>
                    <Button Style="{StaticResource ResourceKey=VisibleRoundButton}"
                            Margin="6,0,0,0"
                            Background="Transparent"
                            BorderThickness="0"
                            Click="minimizeButton_Click"
                            Name="minimizeButton">
                        <Image Source="/OneShoppingList;component/Icons/minimizeWhite.png" Stretch="None"/>
                    </Button>
                    <Button  Style="{StaticResource ResourceKey=RoundButton}"
                            Margin="1,0,0,0"
                            Background="Transparent"
                            BorderThickness="0"
                            Opacity="1"
                            Name="closeButton" 
                            Click="closeButton_Click">
                        <Image Source="/OneShoppingList;component/Icons/BigCrossWhite.png" Stretch="None"/>
                    </Button>
                </StackPanel>
            </Grid>

            <StackPanel Grid.Row="1" Visibility="{Binding IsConnected, Converter={con:BooleanToVisibilityConverter}}"
            Margin="6,3,24,0"
            >
                <TextBlock Text="Add a product to your list:"/>
                <wpftk:AutoCompleteBox
                x:Name="searchBox"
                FontSize="15"
                ItemsSource="{Binding VisibleProducts}"
                FilterMode="ContainsOrdinal"
                MinimumPrefixLength="2"
                SelectionChanged="searchBox_SelectionChanged"
                DropDownClosed="searchBox_DropDownClosed"
                ValueMemberPath="Caption" TextChanged="searchBox_TextChanged">

                    <wpftk:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="0,3,0,3">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="200"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="35"/>
                                    <ColumnDefinition Width="40"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <TextBlock Grid.Row="0" HorizontalAlignment="Left" TextBlock.FontSize="15" Text="{Binding Caption}"/>
                                <TextBlock Grid.Column="2" Grid.Row="0" HorizontalAlignment="Left" TextBlock.FontSize="15" Text="{Binding DefaultQuantity}"/>
                                <TextBlock Grid.Row="1" HorizontalAlignment="Left" Text="{Binding Category}" FontSize="12"/>
                                <TextBlock Grid.Column="2" Grid.Row="1" HorizontalAlignment="Left" Text="{Binding UnitSize}" FontSize="12"/>

                                <Button  Grid.Row="0" Grid.Column="1" 
                                        Name="Puls"
                                        HorizontalAlignment="Right" VerticalAlignment="Top" 
                                        Margin="3,1,3,1"
                                        Style="{StaticResource ResourceKey=RoundButton}"
                                        Command="{Binding Main.IncreaseQuantityCommand, Source={StaticResource Locator}}"
                                        CommandParameter="{Binding}"
                                        Background="White"
                                        BorderThickness="0">

                                    <Image Source="/OneShoppingList;component/Icons/Plus.png" Stretch="None" />

                                </Button>
                                <Button  Grid.Row="1" Grid.Column="1" 
                                        Name="Minus"
                                        HorizontalAlignment="Right" VerticalAlignment="Bottom" 
                                        Margin="3,1,3,1"
                                        Style="{StaticResource ResourceKey=RoundButton}"
                                        Command="{Binding Main.DecreaseQuantityCommand, Source={StaticResource Locator}}"
                                        CommandParameter="{Binding}"
                                        Background="White"
                                        BorderThickness="0">

                                    <Image Source="/OneShoppingList;component/Icons/Minus.png" Stretch="None" />

                                </Button>
                                <Button Grid.Row="0" Grid.RowSpan="2" Grid.Column="3" 
                                    Name="Delete"
                                    HorizontalAlignment="Right" VerticalAlignment="Top" 
                                    Margin="3,3,3,1"
                                    Style="{StaticResource ResourceKey=RoundButton}"
                                    Command="{Binding Main.DeleteItemCommand, Source={StaticResource Locator}}"
                                    CommandParameter="{Binding}"
                                    Background="White"
                                    BorderThickness="0">

                                    <Image Source="/OneShoppingList;component/Icons/Delete.png" Stretch="None" />

                                </Button>
                            </Grid>
                        </DataTemplate>
                    </wpftk:AutoCompleteBox.ItemTemplate>

                </wpftk:AutoCompleteBox>
            </StackPanel>
            <Button Grid.Row="1" Visibility="{Binding IsConnected, Converter={con:BooleanToVisibilityConverter}}"
            Style="{StaticResource ResourceKey=RoundButton}"
            HorizontalAlignment="Right"
            VerticalAlignment="Bottom"
            Margin="3,0,28,5"
            Background="White"
            BorderThickness="0"
            Name="clearButton" 
            Click="clearButton_Click">
                <Image Source="/OneShoppingList;component/Icons/Cross.png" Stretch="None"/>
            </Button>
            <Button Grid.Row="1" Visibility="{Binding IsConnected, Converter={con:BooleanToVisibilityConverter}}"
                Style="{StaticResource ResourceKey=VisibleRoundButton}"
                HorizontalAlignment="Right"
                ToolTip="Add as new Product"
                VerticalAlignment="Bottom"
                Margin="3,0,0,4"
                Background="White"
                BorderThickness="1"
                IsEnabled="False"
                Name="addProductButton" 
                Click="addProductButton_Click">
                <Image Source="/OneShoppingList;component/Icons/BigPlusBlack.png" Stretch="None"/>
            </Button>

            <ListBox Margin="0,6,-6,0" BorderThickness="0" Visibility="{Binding IsConnected, Converter={con:BooleanToVisibilityConverter}}"
                        Name="listBox"
                        HorizontalAlignment="Stretch" Background="Transparent" 
                        HorizontalContentAlignment="Stretch"
                        Grid.Row="2"
                        ItemsSource="{Binding ShoppingList}" 
                        IsSynchronizedWithCurrentItem="True"
                        SelectionChanged="ListBox_SelectionChanged">
                <ListBox.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <TextBlock Margin="6,6,0,0" Text="{Binding Name,  Converter={con:CaseConverter TargetCasing=Upper}}" FontSize="15"/>
                                    <Border Height="1" BorderThickness="1" BorderBrush="DarkGray" Margin="0,0,12,0"/>
                                    <Border Height="1" BorderThickness="1" BorderBrush="LightGray" Margin="0,0,12,-1"/>
                                </StackPanel>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ListBox.GroupStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="0,0,6,0">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid Margin="0,0,6,0"
                                    Visibility="{Binding IsEditing, Converter={con:BooleanToVisibilityConverter IsReversed=True}}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="60"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="24"/>
                                    <RowDefinition Height="24"/>
                                </Grid.RowDefinitions>
                                <StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Left" >
                                    <TextBlock TextBlock.FontSize="15" Text="{Binding Caption}"/>
                                    <Button Name="Edit"
                                        VerticalAlignment="Top" 
                                        Margin="3,2,3,1"
                                        Style="{StaticResource ResourceKey=RoundButton}"
                                        Command="{Binding Main.EditItemCommand, Source={StaticResource Locator}}"
                                        CommandParameter="{Binding}"
                                        Background="White"
                                        Visibility="{Binding IsSelected, Converter={con:BooleanToVisibilityConverter}}"
                                        Click="Edit_Click"
                                        BorderThickness="1">

                                        <Image Source="/OneShoppingList;component/Icons/Edit.png" Stretch="None" />

                                    </Button>

                                </StackPanel>
                                <TextBlock Grid.Column="2" Grid.Row="0" HorizontalAlignment="Left" TextBlock.FontSize="15" Text="{Binding DefaultQuantity}"/>
                                <TextBlock Grid.Row="1" HorizontalAlignment="Left" Text="{Binding PreferredShop}" Margin="0,0,0,0"/>
                                <TextBlock Grid.Column="2" Grid.Row="1" HorizontalAlignment="Left" Text="{Binding UnitSize}"/>
                                <Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" 
                                        Height="1" BorderThickness="1" BorderBrush="LightGray" VerticalAlignment="Top"/>

                                <Button  Grid.Row="0" Grid.Column="2" Grid.RowSpan="2"
                                        Name="Check"
                                        HorizontalAlignment="Right" VerticalAlignment="Top" 
                                        Margin="3,2,6,1"
                                        Style="{StaticResource ResourceKey=RoundButton}"
                                        Command="{Binding Main.RemoveFromShoppingListCommand, Source={StaticResource Locator}}"
                                        CommandParameter="{Binding}"
                                        Background="White"
                                        BorderThickness="1">

                                    <Image Source="/OneShoppingList;component/Icons/Check.png" Stretch="None" />

                                </Button>

                                <Button  Grid.Row="0" Grid.Column="1" 
                                        Name="Puls"
                                        HorizontalAlignment="Right" VerticalAlignment="Top" 
                                        Margin="3,2,3,1"
                                        Style="{StaticResource ResourceKey=RoundButton}"
                                        Command="{Binding Main.IncreaseQuantityCommand, Source={StaticResource Locator}}"
                                        CommandParameter="{Binding}"
                                        Background="White"
                                        Visibility="{Binding IsSelected, Converter={con:BooleanToVisibilityConverter}}"
                                        BorderThickness="1">

                                    <Image Source="/OneShoppingList;component/Icons/Plus.png" Stretch="None" />

                                </Button>
                                <Button  Grid.Row="1" Grid.Column="1" 
                                            Name="Minus"
                                            HorizontalAlignment="Right" VerticalAlignment="Top" 
                                            Margin="3,1,3,1"
                                            Style="{StaticResource ResourceKey=RoundButton}"
                                            Command="{Binding Main.DecreaseQuantityCommand, Source={StaticResource Locator}}"
                                            CommandParameter="{Binding}"
                                            Background="White"
                                            Visibility="{Binding IsSelected, Converter={con:BooleanToVisibilityConverter}}"
                                            BorderThickness="1">

                                    <Image Source="/OneShoppingList;component/Icons/Minus.png" Stretch="None" />

                                </Button>
                            </Grid>
                            <local:EditControl Grid.Row="1" Visibility="{Binding IsEditing, Converter={con:BooleanToVisibilityConverter}}"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <StackPanel 
                Grid.Row="2" Margin="6" 
                Visibility="{Binding IsConnected, Converter={con:BooleanToVisibilityConverter IsReversed=True}}">
                <TextBlock
                    TextWrapping="Wrap" 
                    Margin="0,0,0,12" 
                    Visibility="{Binding IsOneDriveRunning,Converter={con:BooleanToVisibilityConverter IsReversed=True}}">
                    <Run>Microsoft OneDrive desktop app must be running on your system.</Run>
                    <LineBreak/>
                    <Hyperlink NavigateUri="http://onedrive.live.com/about"
                               RequestNavigate="Hyperlink_RequestNavigate">Download Microsoft OneDrive now.</Hyperlink>
                    <LineBreak/>
                    <Run>Note: you might have OneDrive already installed, but not started yet.</Run>
                </TextBlock>
                <TextBlock 
                    Text="Microsoft OneDrive is running"
                    TextWrapping="Wrap" Margin="0,0,0,12" Visibility="{Binding IsOneDriveRunning, Converter={con:BooleanToVisibilityConverter}}"/>
                <TextBlock 
                    Text="Your ONE SHOPPING LIST data are available, but are not being synchronized."
                    TextWrapping="Wrap" Margin="0,0,0,12" Visibility="{Binding DoesProductFileExists, Converter={con:BooleanToVisibilityConverter}}"/>
                <TextBlock
                    TextWrapping="Wrap"
                    Text="Please review the local OneDrive directory:"/>
                <TextBox
                    Grid.Row="4"
                    Margin="0,6"
                    Text="{Binding OneDriveRoot, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

                <TextBlock 
                    TextWrapping="Wrap" 
                    Margin="0,6" 
                    Visibility="{Binding DoesProductFileExists, Converter={con:BooleanToVisibilityConverter IsReversed=True}}">
                    <Run>Make sure you have ONE SHOPPING LIST on your Windows Phone and set it up for sync.</Run>
                    <LineBreak/>
                    <Hyperlink NavigateUri="http://www.windowsphone.com/de-de/store/app/one-shopping-list/d2dbb41e-dd09-4621-b9f1-f6f5d5f7ab1b"
                               RequestNavigate="Hyperlink_RequestNavigate">
                        Install ONE SHOPPING LIST on your Windows phone.</Hyperlink>
                </TextBlock>
                <TextBlock 
                    TextWrapping="Wrap" 
                    Margin="0,0,0,6" 
                    Visibility="{Binding DoesProductFileExists, Converter={con:BooleanToVisibilityConverter IsReversed=True}}">
                    <Run>You must use the same Microsoft account for ONE SHOPPING LIST on your phone and your OneDrive Desktop app.</Run>
                </TextBlock>
                <Button
                    Grid.Row="5"
                    Width="120"
                    Margin="12"
                    HorizontalAlignment="Center"
                    Command="{Binding RetryCommand}"
                    Content="Retry"/>
            </StackPanel>

            <Grid Background="DodgerBlue"
                    Margin="-6,0,-6,-6"
                    Grid.Row="3">
                <TextBlock Margin="12,0,0,0" Text="{Binding ApplicationState}" FontSize="15" Foreground="White"/>
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right"  Margin="0,0,40,0"
                            Visibility="{Binding ShoppingList.Count, Converter={con:BooleanToVisibilityConverter}}">
                    <TextBlock Text="{Binding ShoppingList.Count}" Foreground="White" FontSize="15"/>
                    <TextBlock Text=" Items"  Foreground="White" FontSize="15"/>
                </StackPanel>
            </Grid>

        </Grid>
    </Border>
</Window>
